package com.fhao.friend.controller.question;

import com.fhao.common.core.controller.BaseController;
import com.fhao.common.core.domain.R;
import com.fhao.common.core.domain.TableDataInfo;
import com.fhao.friend.domain.question.dto.QuestionQueryDTO;
import com.fhao.friend.domain.question.vo.QuestionDetailVO;
import com.fhao.friend.domain.question.vo.QuestionVO;
import com.fhao.friend.service.question.IQuestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/question")
public class QuestionController extends BaseController {

    @Autowired
    private IQuestionService questionService;

    @GetMapping("/semiLogin/list")
    public TableDataInfo list(QuestionQueryDTO questionQueryDTO) {
        return questionService.list(questionQueryDTO);
    }

    @GetMapping("/semiLogin/hotList")
    public R<List<QuestionVO>> hotList() {
        return R.ok(questionService.hotList());
    }

    @GetMapping("/detail")
    public R<QuestionDetailVO> detail(Long questionId) {
        return R.ok(questionService.detail(questionId));
    }

    //获取当前题目的上一题或者下一题
    //为了减轻接口的工作量,让这两个接口返回题目id即可然后再去调用题目详情接口获取题目信息.
    //题目排好顺序才方便拿到前后的题目, 所以需要先把题目排序
    //这里可以 利用 redis list数据结构(只存题目id), 虽然题目信息已经用ES缓存去存, 但也不影响用redis排序.
    @GetMapping("/preQuestion")
    public R<String> preQuestion(Long questionId) {
        return R.ok(questionService.preQuestion(questionId));
    }

    @GetMapping("/nextQuestion")
    public R<String> nextQuestion(Long questionId) {
        return R.ok(questionService.nextQuestion(questionId));
    }
}















